package net.comm.page;

import java.util.*;

/**
 * @author mao
 * 
 */

public class TextPageCtr {

    private String Content="";	// 文本内容

	private int TotalNum = 0;	// 文本总长度

	private int PageSize = 10;	// 每页字符数

	private int CurPage = 0; 	// 当前页数

	private int TotalPages = 0; // 总的页数

	private int NextPage = 0; 	// 下一页
	
	private int PrevPage = 0; 	// 上一页
	
	private int PageOne = 0; 	// 显示第一页
	
	private int DisPageNum = 3; // 显示页数
	
	/*
	 * 
	 */
	public TextPageCtr(int currentPage,int pageSize, String content) 
	{
		this.CurPage = currentPage;
		this.PageSize = pageSize;
		this.Content = content;
		this.TotalNum = content.length();

		if(TotalNum%PageSize==0){
			this.TotalPages=TotalNum/PageSize;
	    }else{
	    	this.TotalPages=TotalNum/PageSize+1;
        }

		caculate();
	}

	public void caculate()
	{
		
		/*
		 * 判断如果点击下一页，则判断后面是否还有足够显示的页数，如果不够，则倒推页数，如果足够，则下一页赋值给第一页
		 * 
		 */
		if(CurPage == NextPage){
			if((TotalPages - CurPage) > DisPageNum ) {
				
				PrevPage = CurPage -1;
				if(PrevPage < 0){
					PrevPage = 0;
				}
				PageOne = CurPage;
				NextPage = CurPage + DisPageNum;
				
			}else if((TotalPages - CurPage) == DisPageNum ){//等于
				
				PrevPage = CurPage -1;
				if(PrevPage < 0){
					PrevPage = 0;
				}
				PageOne = CurPage;
				NextPage = 0;	//没有下一页
			}else{
				
				PrevPage = PageOne -1;
				NextPage = 0;	//没有下一页
				PageOne = TotalPages - DisPageNum;
			}
		}else if(CurPage == PrevPage){
			
			if(CurPage > DisPageNum ) {
				
				PageOne = CurPage - DisPageNum;
				PrevPage = PageOne -1;
				if(PrevPage < 0){
					PrevPage = 0;
				}
				NextPage = CurPage;
				
			}else if(CurPage == DisPageNum ){//等于
				
				PageOne = CurPage - DisPageNum;
				PrevPage = PageOne -1;
				if(PrevPage < 0){
					PrevPage = 0;
				}
				NextPage = CurPage;	//没有下一页
			}else{
				
				PageOne = 1;
				PrevPage = 0;
				NextPage = DisPageNum + 1;	//下一页
			}
		}else if(CurPage == 1){

			PageOne = 1;
			if(TotalNum > DisPageNum){
				
				NextPage = PageOne + DisPageNum;
			}else{
				NextPage = 0;
			}
			PrevPage = 0;
		}
	}

	public String getContent() {
		return Content;
	}

	public int getTotalNum() {
		return TotalNum;
	}

	public int getPageSize() {
		return PageSize;
	}

	public int getCurPage() {
		return CurPage;
	}

	public int getTotalPages() {
		return TotalPages;
	}

	public int getNextPage() {
		return NextPage;
	}

	public int getPrevPage() {
		return PrevPage;
	}

	public int getPageOne() {
		return PageOne;
	}

	public int getDisPageNum() {
		return DisPageNum;
	}

	public void setContent(String content) {
		Content = content;
	}

	public void setTotalNum(int totalNum) {
		TotalNum = totalNum;
	}

	public void setPageSize(int pageSize) {
		PageSize = pageSize;
	}

	public void setCurPage(int curPage) {
		CurPage = curPage;
	}

	public void setTotalPages(int totalPages) {
		TotalPages = totalPages;
	}

	public void setNextPage(int nextPage) {
		NextPage = nextPage;
	}

	public void setPrevPage(int prevPage) {
		PrevPage = prevPage;
	}

	public void setPageOne(int pageOne) {
		PageOne = pageOne;
	}

	public void setDisPageNum(int disPageNum) {
		DisPageNum = disPageNum;
	}

}

